package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	
	/**
	 * ...
	 * @author Lisko
	 */
	public class stone extends Sprite 
	{
		static public const COLOR_WHITE:int = 1;
		static public const COLOR_BLACK:int = 0;
		static public const MARGIN_SHADOW:Number = 0.7;
		static private const SHADOW_MARGIN:Number = 1;
		
		public var color:int;
		public var radius:Number;
		public var margins:Number = 2;
		public var shadow:Sprite = new Sprite();
		public var symb:Sprite = new Sprite();
		
		public function stone(color:int, x:int, y:int, radius:Number) 
		{
			addEventListener(Event.ADDED_TO_STAGE, init_ui);
			addEventListener(MouseEvent.MOUSE_OVER, on_stone_over);
			this.color = color;
			this.radius = radius;
			this.x = x;
			this.y = y;
		}
		
		private function on_stone_over(e:MouseEvent):void 
		{
			var xc:int = (parent as board).get_board_coord_x(this.x + parent.x);
			var yc:int = (parent as board).get_board_coord_y(this.y + parent.y);
			//trace(xc, ",", yc, "=", board.stones[xc - 1][yc - 1]);
			//trace(color);
		}
		
		private function init_ui(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init_ui);
			var back_color:int;
			var fore_color:int;
			if (color == stone.COLOR_WHITE)
			{
				back_color = 0xffffff;
				fore_color = 0x000000;
			}
			if (color == stone.COLOR_BLACK) 
			{
				back_color = 0x000000;
				fore_color = 0xffffff;
			}
			shadow.graphics.beginFill(0, 0.5);
			shadow.graphics.drawCircle(0, 0, radius - margins+1);
			shadow.graphics.endFill();
			addChild(shadow);
			shadow.x = SHADOW_MARGIN;
			shadow.y = SHADOW_MARGIN+1;
			symb.graphics.beginFill(back_color);
			symb.graphics.drawCircle(0, 0, radius - margins);
			symb.graphics.endFill();
			symb.graphics.lineStyle(1, fore_color, 0.2);
			symb.graphics.drawCircle(0, 0, radius - margins);
			var glowf:GlowFilter = new GlowFilter(fore_color, 1, 3, 3, 1);
			symb.filters = [glowf];
			addChild(symb);
		}
		
	}

}